<?php
namespace Admin\Widget;
use Think\Controller;
class MenuWidget extends Controller{
    function getMenu(){
        $menu=M('menu');
        $level=M('group')->where(array('id'=>$_SESSION['gid']))->getField('level');
        $level=explode(',', $level);
        $data=array();
        //获取主菜单 pid=0
        $main=$menu->where(array('pid'=>0))->order('sort Desc')->select();
        foreach ($main as $v){
            //获取子菜单下的子菜单的pid=主菜单的id
            $sub=$menu->where(array('pid'=>$v['id']))->order('sort Desc')->select();
            foreach ($sub as $value){
                if(in_array($value['aid'], $level)){
                    $url=M('action')->where(array('id'=>$value['aid']))->getField('url');
                    $value['url']=U($url);
                    $data[$v['title']][]=$value;
                }
                
            }
           
        }
    
        $this->assign('data',$data);
        $this->display('Menu/getmenu');
        //dump($data);
    }
}